package com.neu.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.neu.mapper.EmpMapper;
import com.neu.po.Dept;
import com.neu.po.Emp;
import com.neu.po.EmpExample;
import com.neu.po.Post;
@Service
public class EmpServiceImpl implements EmpService {
	@Autowired
	private EmpMapper empMapper;
	
	@Override
	public Emp getByDept(Dept dept) {
		EmpExample example= new EmpExample();
		example.or().andDeptEqualTo(dept);
		return empMapper.selectByExample(example).get(0);
	}
	
   
	@Override
	public PageInfo<Emp> getPaged(int pageNum, int pageSize) {
		EmpExample example= new EmpExample();  
		PageHelper.startPage(pageNum, pageSize);
		List<Emp> list = empMapper.selectByExample(example);
		
		PageInfo<Emp> pageinfo = new PageInfo<>(list);
		
		return pageinfo;
	}

	@Override
	public int insert(Emp emp) {
		
		
		return empMapper.insert(emp);
	}


	@Override
	public int delete(Emp emp) {
		
		return 0;
	}


	@Override
	public List<Emp> getAll() {
		EmpExample example = new EmpExample();
		
		return empMapper.selectByExample(example);
	}


	@Override
	public List<Emp> getByPost(Post post) {
		EmpExample example = new EmpExample();
		
		example.or().andPostEqualTo(post);
		
		return empMapper.selectByExample(example);
	}


	@Override
	public List<Emp> getById(int id) {
		
		 Emp emp = empMapper.selectByPrimaryKey(id);
		 
		 List<Emp> a = new ArrayList<>();
		 
		 a.add(emp);
		
		return a;
	}


	@Override
	public int update(Emp emp) {
		return empMapper.updateByPrimaryKey(emp);
	}


	

}
